package com.biofuelsfinder;

import android.content.Context;
import android.database.sqlite.*;
import android.util.Log;
import android.database.Cursor;
import android.database.SQLException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

public class biofuelsDB {

    private static final String DATABASE_NAME="mydroiddatabase.db";
    private static final String USER_TABLE_NAME="Users";
    private static final String CREATE_TABLE_RETAILERS="CREATE TABLE IF NOT EXISTS retailers"
   				+ "(name varchar(50) not null, longitude varchar(15)"
  				+ "not null, latitude varchar(15) not null,"
   				+ "address varchar(255) not null, city varchar(50) not null,"
  				+ "state varchar(3), phone varchar(20),"
   				+ "b5 int(1) not null default 0, b10 int(1) not null default 0,"
   				+ "b25 int(1) not null default 0, b50 int(1) not null default 0,"
   				+ "b75 int(1) not null default 0, b100 int(1) not null default 0,"
   				+ "ethanol int(1) not null default 0);";
    private static final int DATABASE_VERSION = 1;
	private SQLiteDatabase myDb=null;
	
	public biofuelsDB(Context ctx){
		myDb = ctx.openOrCreateDatabase(DATABASE_NAME, 0, null);
	}
	
	 public Cursor getRetailers(String fueltype) {
		 System.out.print("Hello");
		 Cursor cursor = null;
		 String query = new String("SELECT * from retailers WHERE " + fueltype + "= 1");
		 try{
			 cursor = myDb.rawQuery(query, null);
		 } catch(SQLException e){
			 Log.e("DBError", e.toString());
		 }
         //ArrayList<Retailer> retailers = new ArrayList<Retailer>();
		 int reccount = cursor.getCount();
         Log.i("DB Call Count", Integer.toString(reccount));         	 
         return cursor;
	 }

}
